package com.example.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.example.model.AddCommentDTO;
import com.example.model.CommentDTO;

@Mapper
public interface CommentMapper {

    @Insert("insert into tb_comment(comment) values(#{comment})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addComment(AddCommentDTO addCommentDTO);

    @Select({
            "<script>",
            "SELECT c.id as commentId, c.comment, u.avatar, u.username, es.score, DATE_FORMAT(es.createAt, '%Y-%m-%d %H:%i') as commentTime FROM tb_comment c join tb_employee_score es on es.userCommentId = c.id join con_user_comment cuc on cuc.commentId = c.id join tb_user u on u.id = cuc.userId WHERE c.id IN ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<CommentDTO> getCommentsByIds(@Param("ids") List<Integer> ids);
}
